import CryptoJS from 'crypto-js'
import config from '../config'

const {
  secret
} = config

export default {
  encrypt(data) {
    return CryptoJS.AES.encrypt(JSON.stringify(data), secret).toString()
  },
  decrypt (data) {
    var bytes  = CryptoJS.AES.decrypt(data, secret)
    var plaintext = bytes.toString(CryptoJS.enc.Utf8)
    return JSON.parse(plaintext)
  }
}